import axios from 'axios';
const API_BASE_URL = process.env.BACKEND_URL;
class FoodPrepTables {
constructor(token) {
this.token = token;
}
async getFoodPrepTables(filter) {
let query = `${API_BASE_URL}/api/FoodPrepTables/`;
if (filter) {
query += `?filter=${JSON.stringify(filter)}&access_token=${this.token}`;
} else {
query += `?access_token=${this.token}`;
}
const res = await axios.get(query);
return res;
}
async updateFoodPrepTables(id, updates) {
if (!id) {
return Promise.reject(new Error('must have id send into patchFoodPrepTables()'));
}
if (Object.keys(updates) === undefined || Object.keys(updates).length < 1) {
return Promise.reject(new Error('must have object with some keys that will be updated. If meant to delete use deleteFoodPrepTables()'));
}
const uri = `${API_BASE_URL}/api/FoodPrepTables/${id}?access_token=${this.token}`;
const res = await axios.patch(uri, updates).catch((err) => Promise.reject(err));
return res;
}
async deleteFoodPrepTables(id) {
if (!id) {
return Promise.reject(new Error('must have id to be able to delete'));
}
const uri = `${API_BASE_URL}/api/FoodPrepTables/${id}?access_token=${this.token}`;
const res = await axios.delete(uri).catch((err) => Promise.reject(err));
return res;
}
async createFoodPrepTables(params, createBlank) {
if (!params && !createBlank) {
return Promise.reject(new Error('createBlank was false and no params were sent in, invalid config'));
}
const uri = `${API_BASE_URL}/api/FoodPrepTables/?access_token=${this.token}`;
if (createBlank && !params) {
const res = await axios.post(uri).catch((err) => Promise.reject(err));
return res;
}